<?php

namespace app\controller\web;

use app\service\OtherClientTableService;
use app\validate\PageValidate;
use app\validate\OtherClientTableValidate;
use share\utils\Helper;

class OtherClientTableController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new OtherClientTableValidate();
    }

    /**
     * 新增支付商户信息
     */
    public function add_action(){
        $input = $this->check();
        $data = OtherClientTableService::addApp($input);
        return self::ok($data);
    }

    /**
     * 修改支付商户信息
     */
    public function edit_action(){
        $input = $this->check();
        $data = OtherClientTableService::updateApp($input);
        return self::ok($data);
    }

    /**
     * 删除支付商户信息
     */
    public function del_action(){
        $input = $this->check();
        $data = OtherClientTableService::delApp($input['appId']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){
        $page = $this->check('pageInfo',null,(new PageValidate()));
        $input = [];       
        $data = OtherClientTableService::getListInfo($input,$page);
        $data = Helper::arrayListReplaceKey($data,[
            'app_id' => 'appId',
            'client_type' => 'clientType',
            'app_secret' => 'appSecret',
            'first_time' => 'firstTime',
            'modify_time' => 'modifyTime',
        ]);
        $total = OtherClientTableService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }

    /**
     * 所有信息
     */
    public function simple_all_action(){
        $data = OtherClientTableService::getAllByFilter([]);
        return self::ok(Helper::listArrayColumn($data,['app_id'=>'appId','message']));
    }

}